<template>
  <div class="app-container" style="overflow: scroll">
    <div style="width: 1024px; margin: 0 auto">
      <el-form ref="submitParams" :model="submitParams" :rules="rules" label-width="160px">
        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="发起参与机构" prop="sender">
              <el-input v-model="submitParams.sender" :disabled="true" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="发起参与机构名" prop="senderName">
              <el-input v-model="submitParams.senderName" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="接收参与机构" prop="directRecver">
              <el-input v-model="submitParams.directRecver" @change="checkbankcode('directRecver')" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label-width="20px">
              <el-button icon="el-icon-search" plain type="primary" @click="openBankBranchDialog('directRecver')">
                行名行号查询
              </el-button>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="18">
            <el-form-item label="接收参与机构名" prop="directRecverName">
              <el-input v-model="submitParams.directRecverName" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="备注" prop="remarks">
              <el-input type="textarea" v-model="submitParams.remarks" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="费用标识" prop="feeId">
              <el-select style="width: 100%" v-model="submitParams.feeId" placeholder="费用标识">
                <el-option
                  v-for="dict in dictMap.FEE_ID"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="统一社会信用代码" prop="uniformScCode">
              <el-input v-model="submitParams.uniformScCode" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="客户标识" prop="custId">
              <el-input type="textarea" v-model="submitParams.custId" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="原报文标识号" prop="oriPkgId">
              <el-input v-model="submitParams.oriPkgId" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label-width="20px">
              <el-button icon="el-icon-search" plain type="primary" @click="oriDetail()">原交易</el-button>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="原发起参与机构" prop="oriSender">
              <el-input v-model="submitParams.oriSender" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="缴款渠道" prop="paymentType">
              <el-select style="width: 100%" v-model="submitParams.paymentType" placeholder="缴款渠道">
                <el-option
                  v-for="dict in dictMap.Pay_Code"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="客户标识类型" prop="custType">
              <el-select style="width: 100%" v-model="submitParams.custType" placeholder="客户标识类型">
                <el-option
                  v-for="dict in dictMap.Cust_Identy_Type_Code"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="特约委收种类代码" prop="spTypeCode">
              <el-input v-model="submitParams.spTypeCode" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="地域标识" prop="regionId">
              <el-input v-model="submitParams.regionId" @change="getbase('RegionId')" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-input v-model="submitParams.regionIdDesc" :disabled="true" />
          </el-col>

          <el-col :span="6">
            <el-form-item label-width="20px">
              <el-button icon="el-icon-search" plain type="primary" @click="openBasedataDialog('RegionId')">
                请选择
              </el-button>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="收款人账户类型" prop="payeeAccType">
              <el-input v-model="submitParams.payeeAccType" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="附加号码内容" prop="addNumContent">
              <el-input type="textarea" v-model="submitParams.addNumContent" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="票据业务类型" prop="billType">
              <el-input v-model="submitParams.billType" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="票据校验码" prop="billChkCode">
              <el-input v-model="submitParams.billChkCode" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="网点编码" prop="branchCode">
              <el-input v-model="submitParams.branchCode" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="代收付中心" prop="institutionId">
              <el-input v-model="submitParams.institutionId" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="付款人名称" prop="payerName">
              <el-input type="textarea" v-model="submitParams.payerName" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="证件类型" prop="idType">
              <el-select style="width: 100%" v-model="submitParams.idType" placeholder="证件类型">
                <el-option
                  v-for="dict in dictMap.Id_Type_Code"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="证件号码" prop="idNum">
              <el-input v-model="submitParams.idNum" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="缴款日期" prop="tradeDate">
              <el-date-picker
                v-model="submitParams.tradeDate"
                style="width: 100%"
                type="date"
                value-format="yyyyMMdd"
              />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="缴费类型" prop="payType">
              <el-select style="width: 100%" v-model="submitParams.payType" placeholder="缴费类型">
                <el-option
                  v-for="dict in dictMap.Pmt_Type_Code"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="缴费人名称" prop="payerName">
              <el-input type="textarea" v-model="submitParams.payerName" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="原报文类型" prop="oriMsgType">
              <el-input v-model="submitParams.oriMsgType" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="付款人账号" prop="payerActno">
              <el-input v-model="submitParams.payerActno" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="付款人开户行行号" prop="payerAccBrno">
              <el-input v-model="submitParams.payerAccBrno" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="收款人名称" prop="payeeName">
              <el-input type="textarea" v-model="submitParams.payeeName" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="收款行行号" prop="payeeBrno">
              <el-input v-model="submitParams.payeeBrno" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="收款人账号" prop="payeeActno">
              <el-input v-model="submitParams.payeeActno" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="收款人开户行行号" prop="payeeAccBrno">
              <el-input v-model="submitParams.payeeAccBrno" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="付款行行号" prop="payerBrno">
              <el-input v-model="submitParams.payerBrno" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="业务类型编码" prop="bizTypeCode">
              <el-select style="width: 100%" v-model="submitParams.bizTypeCode" placeholder="业务类型编码">
                <el-option
                  v-for="dict in dictMap.BIZ_TYPE_363"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="业务种类编码" prop="bizCtgyCode">
              <el-select style="width: 100%" v-model="submitParams.bizCtgyCode" placeholder="业务种类编码">
                <el-option
                  v-for="dict in dictMap.BIZ_CTGY_BEPS_C212"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="缴款总金额币种" prop="totalCurcd">
              <el-input v-model="submitParams.totalCurcd" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="缴款总金额" prop="totalAmt">
              <ht-amount-input
                v-model="submitParams.totalAmt"
                placeholder="缴款总金额"
                :disable="true"
              ></ht-amount-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="需付款行代扣的手续费币种" prop="feeCurcd">
              <el-input v-model="submitParams.feeCurcd" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="需付款行代扣的手续费" prop="feeAmt">
              <ht-amount-input
                v-model="submitParams.feeAmt"
                placeholder="需付款行代扣的手续费"
                :disable="true"
              ></ht-amount-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="备注1" prop="remarks1">
              <el-input type="textarea" v-model="submitParams.remarks1" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="动账标识" prop="accChgFlg">
              <el-select style="width: 100%" v-model="submitParams.accChgFlg" placeholder="动账标识">
                <el-option
                  v-for="dict in dictMap.Acc_Chg_Flg_Code"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="入账通知编号" prop="crdNo">
              <el-input v-model="submitParams.crdNo" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="备注2" prop="remarks2">
              <el-input type="textarea" v-model="submitParams.remarks2" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="经办人" prop="operator">
              <el-input type="textarea" v-model="submitParams.operator" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="明细条数" prop="dtlNum">
              <el-input v-model="submitParams.dtlNum" :disabled="true" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="资金到账情况" prop="fundRcvStatus">
              <el-input v-model="submitParams.fundRcvStatus" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <ht-table
            ref="dataTable"
            :showSerialNumber="false"
            :multi-select="false"
            :opButtonList="opButtonList"
            :tableBindColumns="tableBindColumns"
            :showRightToolbar="false"
            :reqConfig="reqConfig"
            :queryParams="queryParams"
            :initData="false"
            :randomRowKey="true"
            :showPagination="false"
          >
            <template v-slot:operate>
              <el-table-column
                label="操作"
                align="left"
                width="120"
                fixed="right"
                class-name="small-padding fixed-width"
              >
                <template slot-scope="scope">
                  <ht-button-group
                    :buttonList="[
                      {
                        label: '删除',
                        doFunc: () => {
                          remove(scope.row, scope.$index);
                        },
                      },
                    ]"
                  />
                </template>
              </el-table-column>
            </template>
          </ht-table>
        </el-row>
        <el-row>
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[10, 20, 30, 50]"
            :page-size="pageSize"
            layout="->,total, sizes, prev, pager, next, jumper"
            :total="detailList.length">
          </el-pagination>
        </el-row>
      </el-form>

      <div slot="footer" align="center" class="dialog-footer">
        <el-button type="primary" @click="submitForm">提 交</el-button>
        <el-button type="primary" @click="refresh">重 置</el-button>
      </div>

      <bank-branch-dialog ref="bankBranchDialog" @confirm="confirmBankBranch"></bank-branch-dialog>
      <base-data-dialog ref="basedataDialog" @confirm="confirmData"></base-data-dialog>
      <real-time-payment-entry-oir-detail-dailog
        ref="oriDetailDialog"
        @confirm="confirmOridetail"
        :dictMap="this.dictMap"
        :formData.sync="this.formData"
      ></real-time-payment-entry-oir-detail-dailog>

      <real-time-payment-entry-oir-list-dailog
        ref="oriListDialog"
        @confirm="confirmOriList"
        :dictMap="this.dictMap"
        :formData.sync="this.formData"
      ></real-time-payment-entry-oir-list-dailog>
    </div>
  </div>
</template>

<script>
import { listPageMixin } from "@/libs/listPageMixin";
import BankBranchDialog from "@/views/components/BankBranchDialog";
import { getBankInfByBankCode } from "@/api/cnaps/common/bankInfo";
import HtAmountInput from "@/views/components/HtAmountInput";
import { mapGetters } from "vuex";
import { amountThousandsFormatter } from "@/utils/table_col_formatter";
import BaseDataDialog from "@/views/components/BasedataDialog";
import { getBasedata } from "@/api/cnaps/common/basedata";
import RealTimePaymentEntryOirDetailDailog from "@/views/cnaps/beps/363/components/real_time_payment_entry_oriDetail";
import { realTimePaymentEntrydetailTabSearchQuery, realTimePaymentEntrySave } from "@/api/cnaps/beps/363";
import RealTimePaymentEntryOirListDailog from "@/views/cnaps/beps/363/components/real_time_payment_entry_oriList";

export default {
  name: "RealTimePaymentEntry",
  mixins: [listPageMixin],
  components: {
    RealTimePaymentEntryOirListDailog,
    RealTimePaymentEntryOirDetailDailog,
    BaseDataDialog,
    HtAmountInput,
    BankBranchDialog,
  },

  data() {
    return {
      // 录入参数
      submitParams: {
        rspId: "",
        sender: "",
        senderName: "",
        directRecver: "",
        directRecverName: "",
        remarks: "",
        feeId: "",
        uniformScCode: "",
        custId: "",
        oriPkgId: "",
        oriSender: "",
        custType: "",
        spTypeCode: "",
        paymentType: "",
        regionId: "",
        regionIdDesc: "",
        addInfo: "",
        payeeAccType: "",
        addNumContent: "",
        billType: "",
        billChkCode: "",
        branchCode: "",
        institutionId: "",
        payerName: "",
        idType: "",
        idNum: "",
        tradeDate: "",
        payType: "",
        oriMsgType: "",
        payerActno: "",
        payerAccBrno: "",
        payeeName: "",
        payeeBrno: "",
        payeeActno: "",
        payeeAccBrno: "",
        payerBrno: "",
        bizTypeCode: "",
        bizCtgyCode: "",
        totalCurcd: "CNY",
        totalAmt: 0,
        feeCurcd: "CNY",
        feeAmt: 0,
        remarks1: "",
        accChgFlg: "",
        crdNo: "",
        remarks2: "",
        operator: "",
        dtlNum: 0,
        fundRcvStatus: "",
        oriList: [],
      },

      //前端分页参数
      currentPage: 1,
      pageSize: 20,
      detailList: [],

      formData: {},

      reqConfig: realTimePaymentEntrydetailTabSearchQuery,

      queryParams: {},

      loading: false,
      //
      searchFormDictList: [
        "FEE_ID",
        "Cust_Identy_Type_Code",
        "Arrears_Type_Code",
        "Pay_Code",
        "Pay_Query_Type_Code",
        "Id_Type_Code",
        "Pmt_Type_Code",
        "BIZ_TYPE_363",
        "BIZ_CTGY_BEPS_C212",
        "Acc_Chg_Flg_Code",
      ],

      tableBindColumns: [
        { prop: "billCode", label: "账单编号", width: 120 },
        { prop: "payCurcd", label: "缴款金额币种", width: 120 },
        { prop: "payAmt", label: "缴款金额", type: "price", width: 120 },
        { prop: "billCurcd", label: "账单金额币种", width: 120 },
        { prop: "billAmt", label: "账单金额", type: "price", width: 120 },
        { prop: "otFeeCurcd", label: "其他扣费币种", width: 120 },
        { prop: "otFee", label: "其他扣费", type: "price", width: 120 },
        { prop: "serviceCurcd", label: "手续费币种", width: 120 },
        { prop: "serviceAmt", label: "手续费", type: "price", width: 120 },
        { prop: "billDate", label: "账期区间", width: 120 },
        { prop: "paymentInfo", label: "缴费内容", width: 120 },
      ],

      opButtonList: () => {
        return [
          {
            label: "新增",
            type: "primary",
            icon: "el-icon-plus",
            actionType: "add",
            clickFun: () => {
              this.addRow();
            },
          },
        ];
      },

      rules: {
        directRecver: [{ required: true, message: "请输入接收参与机构", trigger: ['blur', 'change'] }],
        remarks: [{ max: 768, message: "长度最大为768位", trigger: "blur" }],
        feeId: [{ required: true, message: "请输入费用标识", trigger: "blur" }],
        uniformScCode: [
          { required: true, message: "请输入统一社会信用代码", trigger: "blur" },
          { max: 18, message: "长度最大为18位", trigger: "blur" },
        ],
        custId: [
          { required: true, message: "请输入客户标识", trigger: "blur" },
          { max: 768, message: "长度最大为768位", trigger: "blur" },
        ],
        oriPkgId: [{ max: 35, message: "长度最大为35位", trigger: "blur" }],
        oriSender: [{ max: 14, message: "长度最大为14位", trigger: "blur" }],
        spTypeCode: [{ max: 6, message: "长度最大为6位", trigger: "blur" }],
        regionId: [{ required: true, message: "请输入地域标识", trigger: ['blur', 'change'] }],
        payeeAccType: [
          { required: true, message: "请输入收款人账户类型", trigger: "blur" },
          { max: 4, message: "长度最大为4位", trigger: "blur" },
        ],
        addNumContent: [{ max: 120, message: "长度最大为120位", trigger: "blur" }],
        billType: [
          { required: true, message: "请输入票据业务类型", trigger: "blur" },
          { max: 20, message: "长度最大为20位", trigger: "blur" },
        ],
        billChkCode: [
          { required: true, message: "请输入票据校验码", trigger: "blur" },
          { max: 20, message: "长度最大为20位", trigger: "blur" },
        ],
        branchCode: [{ max: 20, message: "长度最大为20位", trigger: "blur" }],
        institutionId: [{ max: 14, message: "长度最大为14位", trigger: "blur" }],
        payerName: [{ max: 180, message: "长度最大为180位", trigger: "blur" }],
        idNum: [{ max: 35, message: "长度最大为35位", trigger: "blur" }],
        tradeDate: [{ required: true, message: "请输入缴款日期", trigger: "blur" }],
        payType: [{ required: true, message: "请输入缴费类型", trigger: "blur" }],
        oriMsgType: [{ max: 35, message: "长度最大为35位", trigger: "blur" }],
        payerActno: [
          { required: true, message: "请输入付款人账号", trigger: "blur" },
          { max: 32, message: "长度最大为32位", trigger: "blur" },
        ],
        payerAccBrno: [
          { required: true, message: "请输入付款人开户行行号", trigger: "blur" },
          { max: 14, message: "长度最大为14位", trigger: "blur" },
        ],
        payeeName: [{ max: 180, message: "长度最大为180位", trigger: "blur" }],
        payeeBrno: [
          { required: true, message: "请输入收款行行号", trigger: "blur" },
          { max: 14, message: "长度最大为14位", trigger: "blur" },
        ],
        payeeActno: [
          { required: true, message: "请输入收款人账号", trigger: "blur" },
          { max: 32, message: "长度最大为32位", trigger: "blur" },
        ],
        payeeAccBrno: [
          { required: true, message: "请输入收款人开户行行号", trigger: "blur" },
          { max: 14, message: "长度最大为14位", trigger: "blur" },
        ],
        payerBrno: [
          { required: true, message: "请输入付款行行号", trigger: "blur" },
          { max: 14, message: "长度最大为14位", trigger: "blur" },
        ],
        bizTypeCode: [{ required: true, message: "请输入业务类型编码", trigger: "blur" }],
        bizCtgyCode: [{ required: true, message: "请输入业务种类编码", trigger: "blur" }],
        totalCurcd: [
          { required: true, message: "请输入缴款总金额币种", trigger: "blur" },
          { max: 3, message: "长度最大为3位", trigger: "blur" },
        ],
        totalAmt: [{ required: true, message: "请输入缴款总金额", trigger: "blur" }],
        feeCurcd: [{ max: 3, message: "长度最大为3位", trigger: "blur" }],
        remarks1: [{ max: 768, message: "长度最大为768位", trigger: "blur" }],
        crdNo: [{ max: 30, message: "长度最大为30位", trigger: "blur" }],
        remarks2: [{ max: 768, message: "长度最大为768位", trigger: "blur" }],
        operator: [{ max: 60, message: "长度最大为60位", trigger: "blur" }],
        dtlNum: [{ required: true, message: "请输入明细条数", trigger: "blur" }],
        fundRcvStatus: [{ max: 4, message: "长度最大为4位", trigger: "blur" }],
      },
    };
  },
  mounted() {},

  computed: {
    ...mapGetters(["globalBusData"]),
  },

  created() {
    this.$set(this.submitParams, "sender", this.globalBusData.cnapsBrno);
    this.$set(this.submitParams, "senderName", this.globalBusData.cnapsBrname);
    this.$set(this.submitParams, "operator", this.globalBusData.userId);
  },

  watch: {
    "submitParams.oriList": {
      handler(val) {
        let sum = 0;
        let sum2 = 0;
        val.forEach((v) => {
          sum += parseInt(v.payAmt);
          sum2 += parseInt(v.serviceAmt);
        });
        this.$set(this.submitParams, "totalAmt", sum);
        this.$set(this.submitParams, "feeAmt", sum2);
      },
    },
  },
  methods: {
    //行名行号查询
    openBankBranchDialog(fromFlag = "") {
      this.$refs.bankBranchDialog.show(fromFlag);
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["submitParams"].validate((valid) => {
        if (valid) {
          this.loading = true;
          this.$set(this.submitParams,"oriList",this.detailList)
          realTimePaymentEntrySave(this.submitParams)
            .then((res) => {
              this.$alert(`CORE_ID: ${res.result.rspId}`, "生成交易流水号", {
                confirmButtonText: "确定",
                callback: (action) => {
                },
              });
              this.msgSuccess("录入成功");
              this.refresh();
              this.loading = false;
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },
    //点击重置按钮
    refresh() {
      if (this.$refs.dataTable !== undefined) {
        this.$refs.dataTable.dataList = [];
      }
      this.detailList = [];
      this.resetForm("submitParams");
    },

    //行名行号返回
    confirmBankBranch(fromFlag, row) {
      if (fromFlag === "directRecver") {
        this.$set(this.submitParams, "directRecver", row.bankCode);
        this.$set(this.submitParams, "directRecverName", row.orgFullname);
      }
    },

    checkbankcode(fromFlag) {
      if (fromFlag === "directRecver") {
        let directRecver = this.submitParams.directRecver;
        getBankInfByBankCode(oriSender)
          .then((response) => {
            if (response.code == "S" && response.result !== null && response.result !== undefined) {
              this.$set(this.submitParams, "directRecver", response.result.bankCode);
              this.$set(this.submitParams, "directRecverName", response.result.orgFullname);
            } else {
              this.msgError("无行名行号记录");
              this.$set(this.submitParams, "directRecver", null);
              this.$set(this.submitParams, "directRecverName", null);
            }
          })
          .catch((err) => {
            this.$set(this.submitParams, "directRecver", null);
            this.$set(this.submitParams, "directRecverName", null);
          });
      }
    },

    openBasedataDialog(dataType = "") {
      this.$refs.basedataDialog.show(dataType);
    },

    confirmData(fromFlag, row) {
      this.$set(this.submitParams, "regionId", row.dataValue);
      this.$set(this.submitParams, "regionIdDesc", row.dataDesc);
    },

    //回车获取basedata值
    getbase(dataType) {
      const dataValue = this.submitParams.regionId;
      if (dataValue === "" || dataValue === null || dataValue === undefined) {
        return;
      }

      getBasedata(dataType, dataValue)
        .then((response) => {
          if (response.code == "S" && response.result !== null && response.result !== undefined) {
            this.$set(this.submitParams, "regionId", response.result.dataValue);
            this.$set(this.submitParams, "regionIdDesc", response.result.dataDesc);
          } else {
            this.msgSuccess("找不到对应的字典项");
            this.$set(this.submitParams, "regionId", null);
            this.$set(this.submitParams, "regionIdDesc", null);
          }
        })
        .catch((err) => {
          this.$set(this.submitParams, "regionId", null);
          this.$set(this.submitParams, "regionIdDesc", null);
        });
    },

    remove(row, index) {
      let delIndex = (this.currentPage-1) * this.pageSize + index;
      this.detailList.splice(delIndex, 1);
      this.$refs.dataTable.dataList = this.detailList
      if(index === 0 && this.currentPage !== 1){
        this.handleCurrentChange(this.currentPage-1);
      }else {
        this.handleCurrentChange(this.currentPage);
      }
      this.$set(this.submitParams, "oriList", this.detailList);
      this.$set(this.submitParams, "dtlNum", this.detailList.length);
    },

    addRow() {
      this.$refs.oriListDialog.show();
    },

    confirmOridetail(row) {
      this.$set(this.submitParams, "oriPkgId", row.pkgId);
      this.$set(this.submitParams, "oriMsgType", row.oriMsgType);
      if (row.indirectSender !== "" && row.indirectSender !== null) {
        this.$set(this.submitParams, "oriSender", row.indirectSender);
      } else {
        this.$set(this.submitParams, "oriSender", row.directSender);
      }
      this.$set(this.submitParams, "feeId", row.feeId);
      this.$set(this.submitParams, "uniformScCode", row.uniformScCode);
      this.$set(this.submitParams, "custId", row.custId);
      this.$set(this.submitParams, "regionId", row.regionId);
      this.$set(this.submitParams, "totalCurcd", row.arrearsTotalCurcd);
      this.$set(this.submitParams, "feeCurcd", row.totalBillCurcd);
      this.$set(this.submitParams, "regionIdDesc", row.regionIdDesc);

      this.$set(this.submitParams, "totalAmt", row.arrearsTotalAmt);
      this.$set(this.submitParams, "feeAmt", row.totalBill);
      this.$set(this.queryParams, "oriId", row.id);

      this.$nextTick(() => {
        this.$refs.dataTable.doQuery(true);
      });
    },

    confirmOriList(detailForm) {
      this.$refs.dataTable.dataList.push(detailForm);
      this.detailList.push(detailForm);
      this.$set(this.submitParams, "oriList", this.detailList.dataList);
      this.$set(this.submitParams, "dtlNum",this.detailList.length);
      this.handleCurrentChange(this.currentPage);
    },

    //原交易查询
    oriDetail() {
      this.$set(this.formData, "feeId", this.submitParams.feeId);
      this.$set(this.formData, "uniformScCode", this.submitParams.uniformScCode);
      this.$set(this.formData, "custId", this.submitParams.custId);
      this.$refs.oriDetailDialog.show();
    },

    //前端分页方法
    //切换每页显示数据量时的回调
    handleSizeChange(size) {
      this.pageSize = size;
      this.handleCurrentChange(this.currentPage);
    },
    handleCurrentChange(currentPage) {
      let page = this.detailList.slice((currentPage-1)*this.pageSize,currentPage*this.pageSize);
      this.$refs.dataTable.dataList = page
      this.currentPage = currentPage;
    },
  },
};
</script>
